package org.poem.service;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by poem on 2017/8/27.
 */
@Service
public class ScheduledTaskService {

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");

    @Scheduled(fixedDelay = 500)
    public void reportCurrentTime(){
        System.err.println("每隔5秒执行一次："+dateFormat.format(new Date()));
    }

    @Scheduled(cron = "0 28 11 ? * *")
    public void fixTimeExecution(){
        System.err.println("在指定时间："+ dateFormat.format(new Date())+ "执行.");
    }
}
